package ch13;

import java.util.ArrayList;

public class EditCustomer extends Option {

	// irrelevant stringarray for menu-visualization
	private ArrayList<String> stringArray = new ArrayList<String>();
	private Keypad keypad;

	// EditCustomer constructor
	public EditCustomer(int userID, Screen atmScreen,
			BankDatabase atmBankDatabase, Keypad atmKeypad) {
		super(userID, atmScreen, atmBankDatabase);

		keypad = atmKeypad;
	} // end EditCustomer constructor

	// creates a new customer in the ATM
	public void execute() {
		BankDatabase bankDatabase = getBankDatabase();
		Screen screen = getScreen();
		ArrayList<Customer> customers = bankDatabase.getCustomerList();
		int x = 1; // to run while

		// run while x equals 1
		while (x == 1) {

			stringArray.clear();
			stringArray.add("Enter CustomerID you want to change:  ");
			screen.setKasse(stringArray, 10);
			int customerID = keypad.getInput();

			// loop through customers and see if customer exist
			for (Customer currentCustomer : customers) {
				// if customer exist x equals 1
				if (currentCustomer.getCustomerID() == customerID) {
					x = 1;
					break;
				} else
					// else not x equals 3
					x = 3;

			}// end for loop

			if (x == 3) {// if x equals 3 print out username dosn't exist
				stringArray.clear();
				stringArray.add("username dosn't exist");
				screen.setKasse(stringArray, 10);
			}
			if (x == 1) { // if x equals 1 give option to change customers name
				stringArray.clear();
				stringArray.add("What do you want to change: ");
				stringArray.add("1: first name");
				stringArray.add("2: last name ");
				stringArray.add("3: exit");
				screen.setKasse(stringArray, 10);

				String changeWhat = keypad.getInputS();
				String changeTo;

				switch (changeWhat) { // switch to choose if first or last name
										// admin want to change
				case "1": // change fist name
					stringArray.clear();
					stringArray.add("Enter new first name: ");
					screen.setKasse(stringArray, 10);

					changeWhat = "firstName";
					changeTo = keypad.getInputS();
					bankDatabase.setCustomersName(customerID, changeWhat,
							changeTo);
					break;
				case "2": // change last name
					stringArray.clear();
					stringArray.add("Enter new last name: ");
					screen.setKasse(stringArray, 10);
					changeWhat = "lastName";
					changeTo = keypad.getInputS();
					bankDatabase.setCustomersName(customerID, changeWhat,
							changeTo);
					break;
				case "3": // exit
					x = 2; // x equals 2 for exiting edit

				default:
					x = 2; // x equals 2 for exiting edit
				}// end switch to choose if first or last name

			}// end if x equals 1 give option to change customers name

			// give admin the option to make other changes
			if (x == 1) {
				stringArray.clear();
				stringArray.add("Change made! ");
				stringArray.add("Want to do other changes:");
				stringArray.add("1: Yes");
				stringArray.add("2: No");
				screen.setKasse(stringArray, 10);
				x = keypad.getInput();
			}// end if

		}// end while

	} // end execute method
} // end class EditCustomer